// 已有如下嵌套数组arr，请展开扁平化为[1,2,3,4,5,6,7]
const arr = [1,[2,3],[4,[5,6]],7]

function flat(task, acc) {
    if (!task.length) return acc 
    const [first, ...rest] = task 
    if(Array.isArray(first)) return flat([...first, ...rest], acc)
    return flat(rest,[...acc, first])
}

console.log('flat扁平化后数据',flat(arr,[]))

function flat2(task,acc){
    if (!task.length) return acc.reverse()
    const last = task[task.length-1]
    const front = task.slice(0,task.length-1)
    if(Array.isArray(last)) return flat2(front.concat(last),acc)
    return flat2(front, acc.concat(last))
}

console.log('flat2扁平化后数据',flat2(arr,[]))

console.log('原始数据',arr)